from django.db import models


# Create your models here.
class Idc(models.Model):
    # 机房简称、机房名称、机房地址、机房座机电话、机房负责人姓名、机房负责人邮箱、机房负责人手机号
    name = models.CharField(max_length=10, verbose_name='机房简称')
    name_cn = models.CharField(max_length=20, verbose_name='机房名称')
    address = models.CharField(max_length=100, verbose_name='机房地址')
    phone = models.CharField(max_length=15, verbose_name='机房座机电话')
    username = models.CharField(max_length=5, verbose_name='机房负责人名字')
    user_email = models.CharField(max_length=30, verbose_name='机房负责人邮箱')
    user_phone = models.CharField(max_length=11, verbose_name='机房负责人手机号')

    class Meta:
        default_permissions = []
        permissions = (
            ('add_idc', '添加机房'),
            ('show_idc', '查看机房'),
            ('update_idc', '更新机房'),
            ('delete_idc', '删除机房')
        )


class ServerUser(models.Model):
    # 模型字段：名称、系统用户、系统密码、备注
    # varchar  定长 节省空间 提高查询速度
    name = models.CharField(max_length=10, verbose_name='用户名称')
    username = models.CharField(max_length=10, verbose_name='系统用户')
    password = models.CharField(max_length=16, verbose_name='系统用户密码')
    info = models.TextField(verbose_name='备注信息')

    class Meta:
        default_permissions = []
        permissions = (
            ('add_serveruser', '添加系统用户'),
            ('show_serveruser', '查看系统用户'),
            ('update_serveruser', '更新系统用户'),
            ('delete_serveruser', '删除系统用户')
        )


# 主机模型：IP地址、连接端口、操作系统（Linux，Windows，Mac）、机器类型（虚拟机，物理机）、主机名、CPU型号、CPU物理个数、内存信息、系统平台、系统平台位数、UUID、SN、探测状态、创建主机时间、更新主机时间
class Server(models.Model):
    os_system_tuple = ((1, 'Linux'), (2, 'Windows'), (3, 'Mac'))
    type_tuple = ((1, '虚拟机'), (2, '物理机'))
    scan_status_tuple = ((0, '不在线'), (1, '在线'))
    hostname = models.CharField(max_length=64, verbose_name='主机名称')
    os_system = models.IntegerField(choices=os_system_tuple, verbose_name='操作系统')
    type = models.IntegerField(choices=type_tuple, verbose_name='机器类型')
    cpu_info = models.CharField(max_length=64, verbose_name='CPU信息')
    cpu_count = models.CharField(max_length=2, verbose_name='CPU物理核心数')
    mem_info = models.CharField(max_length=5, verbose_name='内存信息')
    os_system_num = models.CharField(max_length=5, verbose_name='系统平台位数')
    uuid = models.CharField(max_length=64, verbose_name='uuid')
    sn = models.CharField(max_length=64, verbose_name='sn')
    create_date = models.DateTimeField(auto_now_add=True, verbose_name='添加时间')
    update_date = models.DateTimeField(auto_now=True, verbose_name='更新时间')
    scan_status = models.IntegerField(choices=scan_status_tuple, verbose_name='探测状态')


# 硬盘模型：硬盘名、硬盘大小、外键关联（server）
class Disk(models.Model):
    name = models.CharField(max_length=10, verbose_name='硬盘名称')
    size = models.CharField(max_length=10, verbose_name='硬盘大小')
    server = models.ForeignKey('Server')


# 网卡模型：网卡名、ip地址、外键关联（server）
class Network(models.Model):
    name = models.CharField(max_length=10, verbose_name='网卡名称')
    ip = models.CharField(max_length=16, verbose_name='IP地址')
    server = models.ForeignKey('Server')
